package com.wnx.action;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.wnx.db.CollectDao;
import com.wnx.db.ReviewDao;
import com.wnx.entity.Collect;
import com.wnx.entity.Goods;
import com.wnx.entity.Review;
import com.wnx.service.BuyService;

public class BuyAction extends ActionSupport {
	private Goods goods;
	
	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public String execute() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int id = Integer.parseInt(request.getParameter("id"));
		int uid = Integer.parseInt(request.getParameter("uid"));
		BuyService bs = new BuyService();
		List<Goods> goods = bs.getGoodsById(id);
		bs.UpdateClickByid(id);
		CollectDao cd = new CollectDao();
		Collect c = new Collect();
		c.setGid(id);
		c.setUid(uid);
		List<Collect> collect = cd.getCollectStateBygid(c);
		if (goods.size() > 0) {
			
			HttpSession session = request.getSession();
			session.setAttribute("goods", goods.get(0));
			if(collect.size()>0){
				request.setAttribute("collect", collect.get(0));
				System.out.println(collect.get(0).toString());
			}
		}
		;
		return SUCCESS;
	}

}
